#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":processing:rtos"
    module.description = """\
# RTOS Abstractions

Basic building blocks of an RTOS abstracted as C++ classes and implemented
either with FreeRTOS or stdlibc++.
"""

def prepare(module, options):
    if options[":target"].identifier["platform"] not in ["hosted", "stm32"]:
        return False

    if options[":target"].identifier["platform"] not in ["hosted"]:
        module.depends(":freertos",":platform:heap")

    return True

def build(env):
    env.outbasepath = "modm/src/modm/processing/"
    if env.has_module(":freertos"):
        env.copy("freertos", "rtos")
    elif env[":target"].identifier["platform"] in ["hosted"]:
        env.copy("stdlib", "rtos")
        if env[":target"].identifier["family"] in ["linux"]:
            env.collect(":build:library", "pthread")
    else:
        raise BuildException("No RTOS implementation matches your requirements!")
    env.copy("../rtos.hpp", "rtos.hpp")
